var t = getApp();

Page({
    data: {
        layer: !0,
        show_top: !1,
        show_top_scroll: 300,
        scrollHeight: wx.getSystemInfoSync().windowHeight - 130,
        order_key: "",
        region: [ {
            letters: "A",
            regionInfo: [ "安徽", "澳门" ]
        }, {
            letters: "B",
            regionInfo: [ "北京" ]
        }, {
            letters: "C",
            regionInfo: [ "重庆" ]
        }, {
            letters: "F",
            regionInfo: [ "福建" ]
        }, {
            letters: "G",
            regionInfo: [ "广东", "广西", "贵州", "甘肃" ]
        }, {
            letters: "H",
            regionInfo: [ "河北", "河南", "湖北", "湖南", "黑龙江", "海南" ]
        }, {
            letters: "J",
            regionInfo: [ "吉林", "江苏", "江西" ]
        }, {
            letters: "L",
            regionInfo: [ "辽宁" ]
        }, {
            letters: "N",
            regionInfo: [ "宁夏", "内蒙古" ]
        }, {
            letters: "Q",
            regionInfo: [ "青海" ]
        }, {
            letters: "S",
            regionInfo: [ "上海", "四川", "山东", "山西", "陕西" ]
        }, {
            letters: "T",
            regionInfo: [ "天津", "台湾" ]
        }, {
            letters: "X",
            regionInfo: [ "新疆", "西藏", "香港" ]
        }, {
            letters: "Y",
            regionInfo: [ "云南" ]
        }, {
            letters: "Z",
            regionInfo: [ "浙江" ]
        } ],
        list: [],
        order: "",
        orderway: "",
        search_year: "nowyear",
        page: 1,
        location: "",
        city: "",
        city_switch: [],
        city_system_switch: [],
        city_switch_active: 0,
        city_phb: !1,
        top_data: {},
        collectNum: 0
    },
    onShow: function() {
        var t = this;
        t.getList(), wx.getStorageSync("collectNum") && t.setData({
            collectNum: wx.getStorageSync("collectNum")
        });
    },
    onLoad: function(e) {
        var a = this;
        a.setData({
            page: 1,
            list: []
        }), this.data.success && wx.showLoading({
            title: "加载中"
        }), wx.getStorageSync("position") && this.setData({
            location: wx.getStorageSync("position")
        });
        (a = this).data.location, a.data.city;
        var o = JSON.parse(e.data), s = o.order, r = o.orderway, c = o.position;
        a.setData({
            city_phb: !0
        });
        var n = "";
        if (c) {
            console.log("地市"), n = o.province;
            var i = o.city_switch_active, l = o.city;
            a.setData({
                city: l
            });
        } else n = wx.getStorageSync("position");
        wx.request({
            url: t.globalData.request_url + "api/zhiweiku/gk/getSelect.php",
            method: "POST",
            data: {
                act: "getDidqu",
                zwk_sheng: n,
                openid: wx.getStorageSync("openId")
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                if (200 == t.data.code) {
                    for (var e = [ "全部" ], o = 0; o < t.data.data.length; o++) e.push(t.data.data[o]);
                    a.setData({
                        city_switch: e,
                        city_switch_active: i
                    });
                }
            }
        }), a.setData({
            order: s,
            orderway: r
        }), "bkrs" == s && "desc" == r ? this.setData({
            order_key: "bm_hot"
        }) : "jzb" == s && "desc" == r ? this.setData({
            order_key: "jzb_hot"
        }) : "jzb" == s && "asc" == r && this.setData({
            order_key: "jzb_cold"
        });
    },
    onReachBottom: function() {
        var t = this, e = t.data.page;
        e < 10 ? (e++, t.setData({
            page: e
        }), t.getList(!0)) : wx.showToast({
            icon: "none",
            title: "对不起我也是有底线的~"
        });
    },
    getList: function(e) {
        console.log("concat=" + e);
        var a = this, o = a.data.order, s = a.data.orderway, r = a.data.search_year, c = a.data.page, n = a.data.location, i = a.data.city;
        wx.request({
            url: t.globalData.request_url + "api/zhiweiku/gk/getPhb.php",
            method: "POST",
            data: {
                act: "getOrder",
                page: c,
                search_year: r,
                order: o,
                orderway: s,
                zwk_sheng: n,
                zwk_diqu: i,
                openid: wx.getStorageSync("openId")
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                if (200 == t.data.code) {
                    var o = a.data.list;
                    e ? a.setData({
                        list: o.concat(t.data.data)
                    }) : a.setData({
                        list: t.data.data
                    }), a.setData({
                        top_data: {
                            zwnum: t.data.extra.zwnum,
                            zknum: t.data.extra.zknum,
                            bknum: t.data.extra.bknum,
                            jzbnum: t.data.extra.jzbnum,
                            avgnum: t.data.extra.avgnum
                        }
                    }), a.data.success && wx.hideLoading(), a.setData({
                        success: !0
                    });
                }
            }
        });
    },
    changePhb: function(t) {
        var e = this, a = t.currentTarget.dataset.key;
        this.setData({
            order_key: a
        }), "jzb_hot" == a ? e.setData({
            order: "jzb",
            orderway: "desc"
        }) : "jzb_cold" == a ? e.setData({
            order: "jzb",
            orderway: "asc"
        }) : "zl_hot" == a ? e.setData({
            order: "zkrs",
            orderway: "desc"
        }) : "bm_hot" == a ? e.setData({
            order: "bkrs",
            orderway: "desc"
        }) : "bm_cold" == a ? e.setData({
            order: "bkrs",
            orderway: "asc"
        }) : "click_hot" == a && e.setData({
            order: "clicknum",
            orderway: "desc"
        }), e.setData({
            page: 1,
            list: []
        }), e.getList();
    },
    replaceRegion: function(t) {
        var e = this, a = t.currentTarget.dataset.value;
        if ("澳门" == a || "香港" == a || "台湾" == a) return wx.showToast({
            title: "该地区没有数据，请换个地区吧~",
            icon: "none"
        }), !1;
        this.setData({
            location: a,
            layer: !0
        }), e.setData({
            page: 1,
            list: []
        }), e.getList();
    },
    changePhbYear: function(t) {
        var e = this;
        "nowyear" == t.currentTarget.dataset.year ? this.setData({
            search_year: "nowyear"
        }) : this.setData({
            search_year: "lastyear"
        }), e.setData({
            page: 1,
            list: []
        }), e.getList();
    },
    city_change: function(t) {
        var e = this, a = t.currentTarget.dataset.index;
        this.setData({
            city_switch_active: a
        });
        var o;
        0 != a ? (o = e.data.city_switch[a], e.setData({
            city: o
        })) : e.setData({
            city: ""
        }), e.setData({
            page: 1,
            list: []
        }), e.getList();
    },
    closeProvSelect: function() {
        this.setData({
            layer: !0
        });
    },
    changeRegion: function() {
        this.setData({
            layer: !1
        });
    },
    addJob: function(e) {
        var a = this, o = e.currentTarget.dataset.id, s = this.data.list, r = e.currentTarget.dataset.index;
        wx.request({
            url: t.globalData.request_url + "api/zhiweiku/gk/getCollect.php",
            method: "POST",
            data: {
                act: "add_collect",
                openid: wx.getStorageSync("openId"),
                id: o
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                200 == t.data.code ? (wx.showToast({
                    title: "添加成功",
                    icon: "none"
                }), s[r].storage_status = 1, a.setData({
                    list: s
                }), wx.setStorageSync("collectNum", a.data.collectNum + 1), a.setData({
                    collectNum: wx.getStorageSync("collectNum")
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            }
        });
    },
    delJob: function(e) {
        var a = this, o = e.currentTarget.dataset.id, s = this.data.list, r = e.currentTarget.dataset.index;
        wx.request({
            url: t.globalData.request_url + "api/zhiweiku/gk/getCollect.php",
            method: "POST",
            data: {
                act: "del_collect",
                openid: wx.getStorageSync("openId"),
                id: o
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                200 == t.data.code ? (s[r].storage_status = 0, wx.getStorageSync("collectNum") <= 0 ? (wx.setStorageSync("collectNum", 0), 
                a.setData({
                    collectNum: wx.getStorageSync("collectNum")
                })) : (wx.setStorageSync("collectNum", a.data.collectNum - 1), a.setData({
                    collectNum: wx.getStorageSync("collectNum")
                })), a.setData({
                    list: s
                }), wx.showToast({
                    title: "取消成功",
                    icon: "none"
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            }
        });
    },
    go_jobInfo: function(t) {
        var e = t.currentTarget.dataset.id, a = t.currentTarget.dataset.index, o = this.data.list;
        o[a].zwk_jishu++, this.setData({
            list: o
        }), wx.navigateTo({
            url: "../../search/jobInfo/jobInfo?id=" + e
        });
    },
    onPageScroll: function(t) {
        var e = this;
        t.scrollTop <= 0 ? t.scrollTop = 0 : t.scrollTop > wx.getSystemInfoSync().windowHeight && (t.scrollTop = wx.getSystemInfoSync().windowHeight), 
        t.scrollTop > e.data.show_top_scroll ? e.setData({
            show_top: !0
        }) : e.setData({
            show_top: !1
        }), setTimeout(function() {
            e.setData({
                scrollTop: t.scrollTop
            });
        }, 0);
    },
    backTop: function() {
        wx.pageScrollTo({
            scrollTop: 0
        });
    },
    clear_collect: function() {
        wx.setStorageSync("collectNum", 0), this.setData({
            collectNum: wx.getStorageSync("collectNum")
        });
    },
    onShareAppMessage: function() {
        return {
            title: "省考小助手",
            path: "/pages/index/index"
        };
    }
});